<?php
namespace app\admin\controller;
class Server {
    /**
     *当前接口:获取店铺内容信息及管理员
     *传入：openid  用户标识
     */
    public function shopinfo() {
        $searchInfo = db('shopinfo')->find();
        $searchInfo['shop_img'] = 'https://server.entergo.top/' . $searchInfo['shop_url'];
		$bookNumber = Db('booklist')->where('status',1)->select();
        $success = ['queryCode' => '200', 'queryMsg' => '请求成功', 'shopInfo' => $searchInfo,'number'=>$bookNumber];
        return json_encode($success, JSON_UNESCAPED_UNICODE);
    }
    /**
     *当前接口:获取对应sku内容的图书
     *传入：sku  skuID
     */
    public function shopList($skuTap, $sku, $userid, $search, $type) {
        $userAdmin = Db('userinfo')->select();
        if ($userid) {
            foreach ($userAdmin as $key => $val) {
                if ($userid == $userAdmin[$key]['userid']) {
                    if ($userAdmin[$key]['admin_user'] == 1) {
                        if ($type == 1) {
                            $info = Db('booklist')->where('bookname', 'like', '%' . $search . '%')->where('sku', $skuTap)->order('serial_number asc')->limit(0, 8)->select();
                        } else {
                            $info = Db('booklist')->where('bookname', 'like', '%' . $search . '%')->where('second_sku', $sku)->order('serial_number asc')->limit(0, 8)->select();
                        }
                    } else {
                        if ($type == 1) {
                            $info = Db('booklist')->where('bookname', 'like', '%' . $search . '%')->where('sku', $skuTap)->where('status', 1)->order('serial_number asc')->limit(0, 8)->select();
                        } else {
                            $info = Db('booklist')->where('bookname', 'like', '%' . $search . '%')->where('second_sku', $sku)->where('status', 1)->order('serial_number asc')->limit(0, 8)->select();
                        }
                    }
                }
            }
        }
        if (!$userid) {
            if ($type == 1) {
                $info = Db('booklist')->where('bookname', 'like', '%' . $search . '%')->where('status', 1)->where('sku', $skuTap)->order('serial_number asc')->select();
            } else {
                $info = Db('booklist')->where('bookname', 'like', '%' . $search . '%')->where('status', 1)->where('second_sku', $sku)->order('serial_number asc')->select();
            }
        }
        foreach ($info as $key => $val) {
            $info[$key]['number'] = 0;
            $info[$key]['book'] = 'https://server.entergo.top/' . $info[$key]['book_url'];
        }
        $data = ['queryCode' => '200', 'queryMsg' => '请求成功', 'data' => $info];
        return json_encode($data, JSON_UNESCAPED_UNICODE);
    }
    /**
     *当前接口:获取sku内容
     */
    public function shopSku() {
        $info = Db('book_sku')->select();
        $data = ['queryCode' => '200', 'queryMsg' => '请求成功', 'data' => $info];
        return json_encode($data, JSON_UNESCAPED_UNICODE);
    }
    /**
     *当前接口:获取用户openid 唯一标示
     *传入：code 临时识别码
     */
    public function wx_login($code) {
        $APPID = "wx2be16458f583c87b";
        $SECRET = "f33d7ff942920c76353c41a488707847";
        $JSCODE = $code;
        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$APPID}&secret={$SECRET}&js_code={$JSCODE}&grant_type=authorization_code";
        $weixin = file_get_contents($url); //通过code换取网页授权access_token
        $jsondecode = json_decode($weixin); //对JSON格式的字符串进行编码
        $array = get_object_vars($jsondecode); //转换成数组
        $openid = $array['openid']; //输出openid
        return $openid;
    }
    /**
     *当前接口:根据用户id判断是否存入以及查询
     *传入：openid 用户唯一码
     */
    public function userCentent($openid, $nickname, $cover_img, $create_time, $dateDay) {
        $info = Db('userinfo')->where('openid', $openid)->find();
        if ($info) {
            $updatawhere['openid'] = $openid;
            $data['nickname'] = $nickname;
            $data['cover_img'] = $cover_img;
            $infoSelest = Db("userinfo")->where($updatawhere)->update($data);
            $dataInfo = Db('userinfo')->where($updatawhere)->field('userid,nickname,cover_img,admin_user')->find();
        } else {
            $str = '123456789';
            $randStr = str_shuffle($str); //打乱字符串
            $rands = substr($randStr, 0, 6); //substr(string,start,length);返回字符串的一部分
            $data['userid'] = $rands;
            $data['nickname'] = input('nickname');
            $data['cover_img'] = input('cover_img');
            $data['admin_user'] = false;
            $data['openid'] = $openid;
            $data['create_date'] = $create_time;
            $data['dateDay'] = $dateDay;
            $infoSelest = Db('userinfo')->insert($data);
            $dataInfo = Db('userinfo')->where('openid', $openid)->field('userid,nickname,cover_img,admin_user')->find();
        }
        $funde = ['queryCode' => '200', 'queryMsg' => '请求成功', 'userinfo' => $dataInfo];
        return json_encode($funde, JSON_UNESCAPED_UNICODE);
    }
    /**
     *当前接口:根据用户id和shopid查询所添加的商品  加减商品数量
     */
    public function shopcart($shopNum, $shopId, $userId) {
        $info = Db('shop_cart')->where('goodsid', $shopId)->select();
        foreach ($info as $k => $value) {
            if ($info[$k]['userid'] == $userId && $info[$k]['goodsid'] == $shopId) {
                if ($shopNum == 0) {
                    $deleteInfo = Db('shop_cart')->where("(userid = '$userId' and goodsid = '$shopId')")->delete();
                    $funde = ['queryCode' => '200', 'queryMsg' => '删除成功'];
                    return json_encode($funde, JSON_UNESCAPED_UNICODE);
                    die();
                }
                $data['number'] = $shopNum;
                $infoSelest = Db('shop_cart')->where("(userid = '$userId' and goodsid = '$shopId')")->update($data);
                $funde = ['queryCode' => '200', 'queryMsg' => '修改成功'];
                return json_encode($funde, JSON_UNESCAPED_UNICODE);
                die();
            }
        }
        $data['goodsid'] = $shopId;
        $data['userid'] = $userId;
        $data['number'] = $shopNum;
        $infoSelest = Db('shop_cart')->insert($data);
        $funde = ['queryCode' => '200', 'queryMsg' => '添加成功'];
        return json_encode($funde, JSON_UNESCAPED_UNICODE);
    }
    /**
     *当前接口:根据用户id查询所添加的商品
     */
    public function shopCartList($userid) {
        $access = Db('shop_cart')->alias('a')->join('booklist b', 'a.goodsid = b.id', 'INNER')->where("(a.userid = '$userid' and b.status = '1')")->field('userid,number,goodsid,bookname,price,book_url')->select();
        foreach ($access as $key => $val) {
            $access[$key]['book'] = 'https://server.entergo.top/' . $access[$key]['book_url'];
        }
        $funde = ['queryCode' => '200', 'queryMsg' => '请求成功', 'cartList' => $access];
        return json_encode($funde, JSON_UNESCAPED_UNICODE);
    }
    /**
     *当前接口:首页分类商品触底刷新
     */
    public function onCodenum($pages, $type, $sku, $skuTap, $search) {
        $pages = $pages == 1 ? 8 : $pages * 8;
        $userlist = Db('booklist')->where('bookname', 'like', '%' . $search . '%')->where($type == 1 ? 'sku' : 'second_sku', $type == 1 ? $skuTap : $sku)->order('serial_number asc')->limit($pages, 8)->select();
        foreach ($userlist as $key => $val) {
            $userlist[$key]['number'] = 0;
            $userlist[$key]['book'] = 'https://server.entergo.top/' . $userlist[$key]['book_url'];
        }
        $funde = ['queryCode' => '200', 'queryMsg' => '请求成功', 'data' => $userlist];
        return json_encode($funde, JSON_UNESCAPED_UNICODE);
    }
    /**
     *当前接口:获取用户订单详情
     */
    public function getOrderInfo($userid) {
        $info = Db('shop_cart')->alias('a')->join('booklist b', 'a.goodsid = b.id', 'INNER')->where('a.userid', $userid)->field('userid,number,goodsid,bookname,price')->select();
        $count = 0;
        $num = 0;
        foreach ($info as $key => $val) {
            $count+= $info[$key]['price'] * $info[$key]['number'];
            $num = $num + 1;
        }
        $getInfo = ['queryCode' => '200', 'queryMsg' => '请求成功', 'userinfo' => $info, 'shopInfo' => $sa = ['count' => $count + 8, 'total' => $num, 'freight' => '8.00']];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function userPayGoods($goodsList) {
        $name = json_decode($goodsList, true);
        foreach ($name as $k => $v) {
            $shoplist = Db('booklist')->where('id', $name[$k]['goodsid'])->find();
            $num['stock'] = $shoplist['stock'] - $name[$k]['number'];
            if ($num['stock'] < 0) {
                $getInfo = ['queryCode' => '401', 'queryMsg' => $shoplist['bookname'] . '-' . '.库存不足'];
                return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
                die();
            }
        }
        $getInfo = ['queryCode' => '200', 'queryMsg' => '订单有效'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    /**
     *当前接口:获取用户订单详情
     *$userid,$message,$userName,$telNumber,$provinceName,$countyName,$detailInfo,$cityName
     *传入内容参数
     *用户名，留言，收货人姓名，电话，省，市，县（区），详细地址，
     */
    public function onPlaceOrder($userid, $message, $userName, $telNumber, $provinceName, $countyName, $detailInfo, $cityName, $goodsList, $count, $freight, $pay_type) {
        $orderid = $n = 'MH' . date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
        $time = time();
        $data['userid'] = $userid;
        $data['message'] = $message;
        $data['userName'] = $userName;
        $data['telNumber'] = $telNumber;
        $data['provinceName'] = $provinceName;
        $data['countyName'] = $countyName;
        $data['detailInfo'] = $detailInfo;
        $data['cityName'] = $cityName;
        $data['orderId'] = $orderid;
        $data['freight'] = $freight;
        $data['create_time'] = $time;
        $data['order_count'] = $count;
        $data['pay_type'] = $pay_type;
        $name = json_decode($goodsList, true);
        foreach ($name as $k => $v) {
            $shoplist = Db('booklist')->where('id', $name[$k]['goodsid'])->find();
            $num['stock'] = $shoplist['stock'] - $name[$k]['number'];
            if ($num['stock'] < 0) {
                $getInfo = ['queryCode' => '401', 'queryMsg' => $shoplist['bookname'] . '-' . '.库存不足'];
                return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
                die();
            }
        }
        foreach ($name as $k => $v) {
            $shoplist = Db('booklist')->where('id', $name[$k]['goodsid'])->find();
            $num['stock'] = $shoplist['stock'] - $name[$k]['number'];
            Db('booklist')->where('id', $name[$k]['goodsid'])->update($num);
        }
        Db('info_order')->insert($data);
        foreach ($name as $key => $val) {
            $serve['goodsid'] = $name[$key]['goodsid'];
            $serve['goods_number'] = $name[$key]['number'];
            $serve['userid'] = $userid;
            $serve['orderId'] = $orderid;
            $serve['price'] = $name[$key]['price'];
            $serve['bookname'] = $name[$key]['bookname'];
            Db('order_list_user')->insert($serve);
        }
        $deleteInfo = Db('shop_cart')->where("userid", $userid)->delete();
        $getInfo = ['queryCode' => '200', 'queryMsg' => '下单成功', 'orderId' => $orderid];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    /**
     *当前接口查询用户单个订单
     */
    public function getUserOrderInfo($orderId) {
        $info = Db('info_order')->where('orderId', $orderId)->field('userid,message,userName,telNumber,freight,order_count,provinceName,countyName,detailInfo,cityName,orderId,create_time,status,pay_type,express_code,reasons')->find();
        $data = Db('order_list_user')->where('orderId', $orderId)->select();
        $goods = Db('booklist')->select();
        $user = Db('userinfo')->where('userid', $info['userid'])->field('nickname,cover_img,openid')->find();
        foreach ($data as $key => $val) {
            foreach ($goods as $k => $v) {
                if ($data[$key]['goodsid'] == $goods[$k]['id']) {
                    $data[$key]['goodName'] = $data[$key]['bookname'];
                }
            }
        }
        $getInfo = ['queryCode' => '200', 'queryMsg' => '请求成功', 'info' => $info, 'shoplist' => $data, 'user' => $user];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    /**
     * 当前接口：店长查看订单列表('暂时作废')
     */
    public function getOrder() {
        $info = Db('info_order')->field('userid,message,userName,telNumber,freight,order_count,provinceName,countyName,detailInfo,cityName,orderId,create_time,status,pay_type')->select();
        $getInfo = ['queryCode' => '200', 'queryMsg' => '请求成功', 'info' => $info];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    //用户查看自己的订单
    public function getUserOrderInfoList($userid, $orderType) {
        $userinfo = Db('userinfo')->where('userid', $userid)->find();
        if ($userinfo['admin_user'] == 1) {
            $info = Db('info_order')->order('id desc')->where('status', $orderType)->field('userid,message,userName,telNumber,freight,order_count,provinceName,countyName,detailInfo,cityName,orderId,create_time,status,pay_type')->select();
            $data = Db('order_list_user')->select();
        } else {
            $info = Db('info_order')->where('userid', $userid)->where('status', $orderType)->order('id desc')->field('userid,message,userName,telNumber,freight,order_count,provinceName,countyName,detailInfo,cityName,orderId,create_time,status,pay_type')->select();
            $data = Db('order_list_user')->where('userid', $userid)->select();
        }
        $goods = Db('booklist')->select();
        foreach ($data as $key => $val) {
            foreach ($goods as $k => $v) {
                if ($data[$key]['goodsid'] == $goods[$k]['id']) {
                    try {
                        $data[$key]['goodName'] = $data[$key]['bookname'];
                    }
                    catch(Exception $e) {
                        return $e->getMessage();
                        die();
                    }
                }
            }
        }
        $getInfo = ['queryCode' => '200', 'queryMsg' => '请求成功', 'info' => $info, 'shoplist' => $data];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function addTapSku($sukName, $type) {
        if ($type == '999999') {
            $sql = Db('book_sku')->select();
            foreach ($sql as $key => $val) {
                if ($sql[$key]['sukName'] == $sukName) {
                    $getInfo = ['queryCode' => '401', 'queryMsg' => '分类名称请勿重复'];
                    return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
                    die();
                }
            }
            $data['sukName'] = $sukName;
            Db('book_sku')->insert($data);
            $getInfo = ['queryCode' => '200', 'queryMsg' => '添加成功'];
            return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
        } else {
            $sql = Db('second_sku')->select();
            foreach ($sql as $key => $val) {
                if ($sql[$key]['second_sku'] == $sukName) {
                    $getInfo = ['queryCode' => '401', 'queryMsg' => '分类名称请勿重复'];
                    return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
                    die();
                }
            }
            $data['second_sku'] = $sukName;
            $data['parent'] = $type;
            Db('second_sku')->insert($data);
            $getInfo = ['queryCode' => '200', 'queryMsg' => '子分类添加成功'];
            return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
        }
    }
    public function delTapSku($skuid, $type) {
        if ($type == 1) {
            $deleteInfo = Db('book_sku')->where("id", $skuid)->delete();
        } else {
            $deleteInfo = Db('second_sku')->where("id", $skuid)->delete();
        }
        $getInfo = ['queryCode' => '200', 'queryMsg' => '删除成功'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function addGoods($price, $bookname, $book_url, $sku, $stock, $type, $id, $second_sku, $serial_number) {
        $data['price'] = $price;
        $data['bookname'] = $bookname;
        $data['book_url'] = $book_url;
        $data['sku'] = $sku;
        $data['stock'] = $stock;
        $data['second_sku'] = $second_sku;
        $data['serial_number'] = $serial_number;
        if ($type == 1) {
            Db('booklist')->where('id', $id)->update($data);
            $getInfo = ['queryCode' => '200', 'queryMsg' => '修改成功'];
        }
        if ($type == 2) {
            $data['status'] = '1';
            Db('booklist')->insert($data);
            $getInfo = ['queryCode' => '200', 'queryMsg' => '添加成功'];
        }
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onGetCalierAll($userid) {
        $deleteInfo = Db('shop_cart')->where("userid", $userid)->delete();
        $getInfo = ['queryCode' => '200', 'queryMsg' => '清除成功'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onUserAddress($userid) {
        $info = Db('info_order')->where('userid', $userid)->field('userid,userName,telNumber,provinceName,countyName,detailInfo,cityName')->select();
        $getInfo = ['queryCode' => '200', 'queryMsg' => '请求成功', 'info' => $info];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onGoodsInfo($goodsid) {
        $info = Db('booklist')->where('id', $goodsid)->find();
        $info['book'] = 'https://server.entergo.top/' . $info['book_url'];
        $getInfo = ['queryCode' => '200', 'queryMsg' => '请求成功', 'info' => $info];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function allUserlist() {
        $info = Db('userinfo')->order('admin_user desc')->select();
        $getInfo = ['queryCode' => '200', 'queryMsg' => '请求成功', 'info' => $info];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onDeleteGoods($goodsid) {
        $deleteInfo = Db('booklist')->where("id", $goodsid)->delete();
        $getInfo = ['queryCode' => '200', 'queryMsg' => '删除成功'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onGoodsState($goodsid, $status) {
        $data['status'] = $status;
        Db('booklist')->where('id', $goodsid)->update($data);
        $getInfo = ['queryCode' => '200', 'queryMsg' => '修改成功'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onOrderState($orderId, $status, $code) {
        $data['status'] = $status;
        $data['express_code'] = $code;
        Db('info_order')->where('orderId', $orderId)->update($data);
        $getInfo = ['queryCode' => '200', 'queryMsg' => '修改成功'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onOrderUserState($orderId, $status) {
        $data['status'] = $status;
        Db('info_order')->where('orderId', $orderId)->update($data);
        $getInfo = ['queryCode' => '20011', 'queryMsg' => '修改成功'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onOrderSearch($search, $userid, $orderType) {
        $userinfo = Db('userinfo')->where('userid', $userid)->find();
        if ($userinfo['admin_user'] == 1) {
            $info = Db('info_order')->where('orderId', 'like', '%' . $search . '%')->where('status', $orderType)->order('id desc')->field('userid,message,userName,telNumber,freight,order_count,provinceName,countyName,detailInfo,cityName,orderId,create_time,status')->select();
            $data = Db('order_list_user')->where('orderId', 'like', '%' . $search . '%')->select();
        }
        if ($userinfo['admin_user'] != 1) {
            $info = Db('info_order')->where('orderId', 'like', '%' . $search . '%')->where('userid', $userid)->order('id desc')->field('userid,message,userName,telNumber,freight,order_count,provinceName,countyName,detailInfo,cityName,orderId,create_time,status')->select();
            $data = Db('order_list_user')->where('orderId', 'like', '%' . $search . '%')->where('userid', $userid)->select();
        }
        $goods = Db('booklist')->select();
        foreach ($data as $key => $val) {
            foreach ($goods as $k => $v) {
                if ($data[$key]['goodsid'] == $goods[$k]['id']) {
                    $data[$key]['goodName'] = $goods[$k]['bookname'];
                    $data[$key]['price'] = $goods[$k]['price'];
                }
            }
        }
        $getInfo = ['queryCode' => '200', 'queryMsg' => '请求成功', 'info' => $info, 'shoplist' => $data];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onAdminisaction($userid, $type) {
        $data['admin_user'] = $type;
        Db('userinfo')->where('userid', $userid)->update($data);
        $getInfo = ['queryCode' => '200', 'queryMsg' => '修改成功'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onUpdataShopInfo($shop_name, $shop_phone, $shop_address, $shop_url, $lat, $lon, $id, $freight) {
        $data['shop_name'] = $shop_name;
        $data['shop_phone'] = $shop_phone;
        $data['shop_address'] = $shop_address;
        $data['shop_url'] = $shop_url;
        $data['lat'] = $lat;
        $data['lon'] = $lon;
        $data['freight'] = $freight;
        Db('shopinfo')->where('id', $id)->update($data);
        $getInfo = ['queryCode' => '200', 'queryMsg' => '修改成功'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function searchSku() {
        $info = Db('second_sku')->select();
        $getInfo = ['queryCode' => '200', 'queryMsg' => '修改成功', 'data' => $info];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function onLastOrder($userid, $orderId,$reasons) {
        $orderInfo = Db('info_order')->where('orderId', $orderId)->find();
        if ($orderInfo['status'] == '100') {
            $queryCode = '402';
            $queryMsg = '用户已收到货，无法操作';
        } else if ($orderInfo['status'] == '102') {
            $queryCode = '403';
            $queryMsg = '店主已确认，请联系店主微信取消';
        } else {
            $data['status'] = 104;
			$data['reasons'] = $reasons;
            Db('info_order')->where("orderId",$orderId)->update($data);
            $queryCode = '200';
            $queryMsg = '取消成功';
        }
        $getInfo = ['queryCode' => $queryCode, 'queryMsg' => $queryMsg];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function upDateSku($sukName, $type) {
        $data['sukName'] = $sukName;
        Db('book_sku')->where('id', $type)->update($data);
        $getInfo = ['queryCode' => '200', 'queryMsg' => '修改成功'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
    public function Sku_second_sku($sukName, $type) {
        $data['second_sku'] = $sukName;
        Db('second_sku')->where('id', $type)->update($data);
        $getInfo = ['queryCode' => '200', 'queryMsg' => '修改成功'];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
    }
	/**
     *当前接口：获取模板token
     */
	public function access_token() {
		$APPID="wx2be16458f583c87b";
		$SECRET="f33d7ff942920c76353c41a488707847";
		$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$APPID&secret=$SECRET";
		$weixin = file_get_contents($url);
		//通过code换取网页授权access_token
		$jsondecode=json_decode($weixin);
		//对JSON格式的字符串进行编码
		$array = get_object_vars($jsondecode);
		//转换成数组
		return $array['access_token'];
	}
	//订单快递发货通知
    public function onShippingReminder($openid,$orderid,$goodName,$scanCode,$data) {
        $post_data = array("touser" => $openid, "template_id" => 'xD-KyDdMxQ12q1EGHRavUvnAzVlGlGL2tq5UVD-K-qk', "page" => 'pages/orderinfo/orderinfo?orderId=' . $orderid, 'data' => ['character_string1' => ['value' => $orderid], 'thing2' => ['value' => $goodName], 'character_string4' => ['value' => $scanCode], 'date5' => ['value' => '20' . $data]]);
        $url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" . $this->access_token();
        $options = array('http' => array('method' => 'POST', 'header' => 'Content-type:application/json', 'content' => json_encode($post_data), 'timeout' => 60));
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
		var_dump($result);
    }
	//快递城乡配送通知
	public function onShippingRural($openid,$orderid,$goodName,$data){
		$post_data = array("touser" => $openid, "template_id" => 'xD-KyDdMxQ12q1EGHRavUrbkQgO2Oc8oiVqCmHFOF9Y', "page" => 'pages/orderinfo/orderinfo?orderId=' . $orderid, 'data' => ['character_string1' => ['value' => $orderid], 'thing2' => ['value' => $goodName], 'phrase3' => ['value' => '城乡配送'], 'date5' => ['value' => '20' . $data]]);
        $url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" . $this->access_token();
        $options = array('http' => array('method' => 'POST', 'header' => 'Content-type:application/json', 'content' => json_encode($post_data), 'timeout' => 60));
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
		var_dump($result);
	}
	//快递取消通知
	public function onCancelOrders($openid,$orderid,$reasons){
		$post_data = array("touser" => $openid, "template_id" => 'epKeR8qwdNnq1sCAYUvhxECCrt4pyEOeI1LaMGSdTsg', "page" => 'pages/orderinfo/orderinfo?orderId=' . $orderid, 'data' => ['character_string1' => ['value' => $orderid], 'thing7' => ['value' => $reasons]]);
        $url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" . $this->access_token();
        $options = array('http' => array('method' => 'POST', 'header' => 'Content-type:application/json', 'content' => json_encode($post_data), 'timeout' => 60));
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
		$getInfo = ['queryCode' => $result, 'queryMsg' => $reasons];
        return json_encode($getInfo, JSON_UNESCAPED_UNICODE);
	}

}
